package strings;

import java.util.regex.Pattern;

//parse an integer from a string

public class ParseIntegerFromString {

	static class IntegerParsingException extends RuntimeException {
		
	}
	
	public static Integer parseInteger(String s) throws IntegerParsingException {
		
		int result = 0;
		
		if (s == null) {
			throw new IntegerParsingException();
		}
			
		if (!Pattern.matches("(([1-9]\\d*)|0)", s)) {
			throw new IntegerParsingException();
		}
		int length = s.length();
		for (int i=0; i<s.length(); i++) {
			result += pow(length-1-i) * ((int)s.charAt(i)-48);
		}
		
		return result;
	}
	
	private static int pow(int d) {
		return (int) Math.pow(10, d);
	}
	
	public static void main(String []args) {
		
		
		String s = "556545.99";
		System.err.println(s.split("\\.")[1]);
		
		Integer i = parseInteger("102655");
		
		i += 1;
		
		System.err.println(i);
		
	}
}
